package com.example.webone.controller;

import com.example.webone.mapper.ManMapper;
import com.example.webone.pojo.Man;
import com.example.webone.services.Impl.ManServiceImpl;
import com.example.webone.services.ManService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/man")
public class ManController {

    @Autowired
    ManServiceImpl manService;

    // 获取所有man信息
    @GetMapping("/getAllMan")
    public List<Man> getEmployees(){
        List<Man> men = manService.getAllMan();
        return men;
    }

    //获取指定man的信息
    @GetMapping("/getMan/{id}")
    public Man getMan(@PathVariable("id")int id){
        Man man = manService.getMan(id);
        return man;
    }

    //插入一个man到数据库
    @GetMapping("/insertMan")
    public String insertMan(@RequestParam("id") int id,
                            @RequestParam("name") String name){
        Man man = new Man(id,name);
        int isSuccess = manService.insertMan(man);
        if(isSuccess == 1){
            return "Success";
        }else {
            return "Fail";
        }
    }
    //插入一个man到数据库使用map方式
    @GetMapping("/addMan")
    public String addMan(){
        Map<String,Object> map = new HashMap<>();
        map.put("name","Jill");
        map.put("id",120);
        int isSuccess = manService.addMan(map);
        if(isSuccess == 1){
            return "Success";
        }else {
            return "Fail";
        }
    }



}
